﻿// ***************************************************************************
// MapLook
// Copyright (C) 2009 Christian Schmiljun
// http://maplook.codeplex.com
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
// ***************************************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace MapLook2007
{
    public partial class FormMap : Form
    {
        private MapService map;
        private string location;

        public FormMap()
        {
            InitializeComponent();

            // init map browser            
            switch (global::MapLook2007.Properties.Settings.Default.mapProviderIndex)
            {
                case 0:
                    this.map = new MapGoogle();
                    googleToolStripMenuItem.Enabled = false;
                    break;
                case 1:
                    this.map = new MapVirtualEarth();
                    virtualEarthToolStripMenuItem.Enabled = false;
                    break;
                default:
                    this.map = new MapGoogle();
                    googleToolStripMenuItem.Enabled = false;
                    break;
            }
            this.panel1.Controls.Add(this.map);

            this.map.AccessibleDescription = null;
            this.map.AccessibleName = null;
            this.map.MinimumSize = new System.Drawing.Size(20, 20);
            this.map.Name = "webBrowser1";
            this.map.Dock = DockStyle.Fill;
            
        }

        public void SetLocationByDescription(string location)
        {
            ((MapService)map).SetLocationByDescription(location);
            this.location = location;
        }

        private void infoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new AboutBox1().ShowDialog();
        }

        private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void googleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpdateMapProvider(0);
        }

        private void UpdateMapProvider(int p)
        {
            global::MapLook2007.Properties.Settings.Default.mapProviderIndex = p;
            global::MapLook2007.Properties.Settings.Default.Save();

            FormMap mapForm = new FormMap();
            mapForm.Show();
            mapForm.SetLocationByDescription(location);

            this.Close();
        }

        private void virtualEarthToolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpdateMapProvider(1);
        }
    }
}
